package cn.springcloud.fix.common.starter.event;

import cn.springcloud.fix.common.core.base.Unique;
import cn.springcloud.fix.common.core.utils.SpringUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEvent;

import java.io.Serializable;
import java.util.Date;

@Slf4j
@Getter
@Setter
public class DomainEvent<S extends Serializable> extends ApplicationEvent implements Unique<Long> {

    /**
     * 事件ID
     */
    private Long eventId;

    /**
     * 事件创建时间
     */
    private Date occurredOn;

    /**
     * 事件描述
     */
    private String description;

    public DomainEvent(Object source) {
        super(source);
    }

    @Override
    public Long getUID() {
        return this.eventId;
    }

    public void fire() {
        SpringUtil.publishEvent(this);
    }
}
